# -*- encoding: utf-8 -*-
from django.conf.urls.defaults import *
from wagglyblog.models import Post, Category

blog_dict = {
    'queryset': Post.published.all(),
}

category_dict = {
    'queryset' : Category.objects.all(),
}

blog_date_dict = dict(blog_dict, date_field='pub_date')
month_dict = dict(blog_date_dict, month_format='%m')

urlpatterns = patterns('django.views.generic.date_based',
    (r'^$', 'archive_index', blog_date_dict, 'wagglyblog_archive_index'),
    (r'^(?P<year>\d{4})/$', 'archive_year', blog_date_dict, 'wagglyblog_archive_year'),
    (r'^(?P<year>\d{4})/(?P<month>\d{1,2})/$', 'archive_month', month_dict, 'wagglyblog_archive_month'),
    (r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', 'archive_day', month_dict, 'wagglyblog_archive_day'),
    (r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$', 'object_detail', dict(month_dict, slug_field='slug'), 'wagglyblog_post_detail'),
)

urlpatterns += patterns('django.views.generic.list_detail',
    # WARNING: collides with archive_year!
    (r'^(?P<object_id>\d+)/$', 'object_detail', blog_dict, 'wagglyblog_short_detail'),
    (r'^categories/$', 'object_list', category_dict, 'wagglyblog_categories'),
)

urlpatterns += patterns('wagglyblog.views',
    url(r'^authors/$', 'author_list', name='wagglyblog_author_list'),
    url(r'^authors/(?P<username>[-\w]+)/$', 'author', name='wagglyblog_author'),
    url(r'^add/$', 'add', name='wagglyblog_addpost'),

    # possible with generic wrapper !
    url(r'^categories/(?P<slug>[-\w+]+)/$', 'category_postlist', name='wagglyblog_category'),
)
